package org.groupg.practice.document;

public class Application {
    public static void main(String[] args) {
        // 初始化存储
        DocumentStore store = new DocumentStore("business_data.db");

        // 初始化异步服务
        AsyncMetricService metricService = new AsyncMetricService(store, 4);

        // 创建业务文档
        BusinessDocument userDoc = new BusinessDocument("user-123", "USER_ANALYTICS");
        store.saveDocument(userDoc);

        BusinessDocument productDoc = new BusinessDocument("prod-456", "PRODUCT_METRICS");
        store.saveDocument(productDoc);

        // 提交计算任务
        metricService.submitMetricTask("USER_ANALYTICS", "user-123");
        metricService.submitMetricTask("PRODUCT_METRICS", "prod-456");

        // 稍后获取结果
        try {
            Thread.sleep(2000); // 等待计算完成

            BusinessDocument updatedUser = store.getDocument("USER_ANALYTICS", "user-123");
            System.out.println("User metrics: " + updatedUser.getMetrics());

            BusinessDocument updatedProduct = store.getDocument("PRODUCT_METRICS", "prod-456");
            System.out.println("Product metrics: " + updatedProduct.getMetrics());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } finally {
            metricService.shutdown();
            store.close();
        }
    }
}
